package com.hang.mapstruct;

import com.hang.entity.Item;
import com.hang.model.dto.request.ItemModelDTO;
import com.hang.model.dto.response.ItemInfoModel;
import com.hang.model.vo.ItemInfoDetailModel;
import org.mapstruct.Mapper;

import java.util.LinkedList;
import java.util.List;

@Mapper(componentModel = "spring")
public interface ItemMapStruct {
    Item itemModelDTOToItem(ItemModelDTO itemModelDTO);

    ItemInfoModel itemToItemInfoModel(Item item);

    default List<ItemInfoModel> itemListToItemInfoModelList(List<Item> records){
        List<ItemInfoModel> itemInfoModelList = new LinkedList<>();
        records.forEach(
                record ->{
                    itemInfoModelList.add(itemToItemInfoModel(record));
                }
        );

        return itemInfoModelList;
    }

    //基础数据的映射
    ItemInfoDetailModel itemToItemInfoDetailModel(Item dbItem);
}
